/**
 * 1737. 括号的最大嵌套深度
 * https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses/
 */

const paranLeftCode = '('.charCodeAt(0);
const paranRightCode = ')'.charCodeAt(0);

/**
 * @param {string} s
 * @return {number}
 */
function maxDepth(s) {
  const stack = new Array(s.length).fill(0);
  let top = -1;
  let max = 0;
  for (let i = 0; i < s.length; i += 1) {
    const code = s.charCodeAt(i);
    if (code === paranRightCode) {
      max = Math.max(max, top + 1);
      top -= 1;
    } else if (code === paranLeftCode) {
      top += 1;
      stack[top] = code;
    }
  }
  return max;
}

console.log(maxDepth('') === 0);
console.log(maxDepth('1') === 0);
console.log(maxDepth('(1+(2*3)+((8)/4))+1') === 3);
console.log(maxDepth('(1)+((2))+(((3)))') === 3);
console.log(maxDepth('1+(2*3)/(2-1)') === 1);
